﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Storage;
using Windows.Storage.BulkAccess;
using Windows.Storage.Search;
using Windows.UI.Xaml.Data;

namespace ImageBinding.DataModel
{
    public class DataSource:INotifyPropertyChanged
    {
        object _items;
        public object Items
        {
            get { return _items; }
            private set
            {
                _items = value;
                onPropertyChanged("Items");
            }
        }

        public DataSource()
        {
            try
            {
                var queryOptions = new Windows.Storage.Search.QueryOptions();
                queryOptions.FolderDepth = FolderDepth.Deep;
                var query = KnownFolders.PicturesLibrary.CreateFileQueryWithOptions(queryOptions);
                var fileInformationFactory = new FileInformationFactory(query,
                    Windows.Storage.FileProperties.ThumbnailMode.PicturesView,
                    150, Windows.Storage.FileProperties.ThumbnailOptions.UseCurrentScale, true);
                Items = fileInformationFactory.GetVirtualizedFilesVector();
            }
            catch (Exception ex)
            {
                Items = new object[] {new{ Name = ex.Message} };
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
        private void onPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}
